<?php
class ArtcCheckAction extends BaseAction {
	public function index() {
		$dao = D ( "Artc" );
		
		//排序字段 默认为主键名
		if (isset ( $_REQUEST ['_order'] )) {
			$order = $_REQUEST ['_order'];
		} else {
			$order = ! empty ( $sortBy ) ? $sortBy : $dao->getPk ();
		}
		//排序方式默认按照倒序排列
		//接受 sost参数 0 表示倒序 非0都 表示正序
		if (isset ( $_REQUEST ['_sort'] )) {
			$sort = $_REQUEST ['_sort'] ? 'asc' : 'desc';
		} else {
			$sort = $asc ? 'asc' : 'desc';
		}
		
		//过滤条件
		$checked = ( int ) $_REQUEST ['checked'];
		
		$map ['checked'] = $checked;
		$this->assign ( 'checked', $checked );
		
		if (isset ( $_REQUEST ['title'] ) && ! empty ( $_REQUEST ['title'] )) {
			$map ['title'] = array ('like', $_REQUEST ['title'] . '%' );
			$this->assign ( 'title', $_REQUEST ['title'] );
		}
		
		if (isset ( $_REQUEST ['author'] ) && ! empty ( $_REQUEST ['author'] )) {
			$map ['author'] = $_REQUEST ['author'];
			$this->assign ( 'author', $map ['author'] );
		}
		
		if (isset ( $_REQUEST ['date'] ) && ! empty ( $_REQUEST ['date'] )) {
			$map ['date'] = $_REQUEST ['date'];
			$this->assign ( 'date', $map ['date'] );
		}
		
		//取得满足条件的记录数
		$count = $dao->where ( $map )->count ( 'id' );
		$this->assign('count',$count);
		if ($count > 0) {
			import ( "ORG.Util.Page" );
			//创建分页对象
			if (! empty ( $_REQUEST ['listRows'] )) {
				$listRows = $_REQUEST ['listRows'];
			} else {
				$listRows = '';
			}
			$p = new Page ( $count, $listRows );
			//分页查询数据
			

			$voList = $dao->where ( $map )
				->order ( "`" . $order . "` " . $sort )
				->limit ( $p->firstRow . ',' . $p->listRows )
				->findAll ();
			//echo $model->getlastsql();
			//分页跳转的时候保证查询条件
			foreach ( $map as $key => $val ) {
				if (! is_array ( $val )) {
					$p->parameter .= "$key=" . urlencode ( $val ) . "&";
				}
			}
			//分页显示
			$page = $p->show ();
			//列表排序显示
			$sortImg = $sort; //排序图标
			$sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列'; //排序提示
			$sort = $sort == 'desc' ? 1 : 0; //排序方式
			//模板赋值显示
			$this->assign ( 'list', $voList );
			$this->assign ( 'sort', $sort );
			$this->assign ( 'order', $order );
			$this->assign ( 'sortImg', $sortImg );
			$this->assign ( 'sortType', $sortAlt );
			$this->assign ( "page", $page );
		}
		
		$this->assign ( 'img_dir', C ( 'ARTC_IMG_DIR' ) . 's_' );
		Cookie::set ( '_currentUrl_', __SELF__ );
		
		$this->display ();
	}
	
	public function setCheck() {
		$arr_id = $_REQUEST ['id'];
		if (empty ( $arr_id ) || ! is_array ( $arr_id )) {
			$this->error ( '非法操作！' );
		}
		
		
		
		$dao = D ( 'Artc' );
		$condition = array ('id' => array ('in', join ( ',', $arr_id ) ) );
		$bSet = ( int ) $_REQUEST ['bSet'];
		
		$rt = $dao->where( $condition )->setField ( 'checked', $bSet );
		if ($rt !== FALSE) {
			//$this->_refresh_left($pid);
			$this->assign ( 'jumpUrl', __URL__ . '/index/checked/'.$bSet );
			$this->success ( '操作成功！' );
		} else {
			$this->error ( '审核文章失败！' );
		}
	
	}

}

?>